#!/usr/bin/env bash
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
# Function :CentOS7.X  KMS激活服务器
# Platform :RedHatEL7.x Based Platform
# Version  :1.02
# Date     :2022-10-31
# Author   :mugoLH
# Contact  :hxsaj@126.com
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
#  变量列表 List of common variables
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
#  获取主机名列的源文件
kms_file_url="https://cangshui.net/-down/-mytargz/vlmcsd-2018.zip"


#  函数列表 Function list
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
info_p(){    printf "\e[1;35;40m%-8s %-20s %-24s %-2s %-2s\e[0m\n" "$(date '+%H:%M:%S')" "${1}" "${2}" "${3}" "${4}" >&1 ;}

#  检查软件是否满足需求
if [[ $(rpm -qa | grep wget | wc -l) -ge 1 ]] || [[ $(rpm -qa | grep unzip | wc -l) -ge 1 ]];then
	yum install -y wget unzip
fi

#  下载KMS文件
info_p "[ 下载KMS文件 ]......" && wget --no-check-certificate ${kms_file_url}
#  解压文件
if [[ -f vlmcsd-2018.zip ]];then
	unzip -q vlmcsd-2018.zip -d /usr/local/ &&  ln -sv /usr/local/vlmcsd-2018/ /usr/local/KMS
else
	echo -e "kms文件不存在，请检查！"
	exit
fi
#  加入PATH路径生效
info_p "[ PATH路径生效 ]......"
echo "export PATH=/usr/local/KMS/binaries/Linux/intel/static:\$PATH" > /etc/profile.d/vlmcs.sh
source /etc/profile.d/vlmcs.sh
chmod +x /usr/local/KMS/binaries/Linux/intel/static/*
echo "vlmcsd-x64-musl-static" >> /etc/rc.local

#  启动服务
info_p "[ 启动KMS服务 ]......"
vlmcsd-x64-musl-static
netstat -anltp | grep 1688





